<script setup>
import { ref } from 'vue'
import { onBeforeMount} from 'vue'
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'
import { RouterLink,useRouter } from 'vue-router';
let router = useRouter()
let user = ref({})
onBeforeMount(()=>{
  let localUser = JSON.parse(localStorage.getItem('user'))
  if(localUser){
    user.value = localUser
  }else{
    router.push('/login') 
  }
})
user.value = JSON.parse(localStorage.getItem('user'))
function handleExit(){
  localStorage.removeItem('user')
  router.push('/login')
}
const isCollapse = ref(false)

</script>

<template>
  <el-container>
    <el-aside width="160px">
      <el-menu default-active="2" :collapse="isCollapse" :router="true">
        <el-menu-item index="/">
          <el-icon><icon-menu /></el-icon>
          <template #title>首页</template>
        </el-menu-item>
        <el-sub-menu index="2">
          <template #title>
            <el-icon>
              <location />
            </el-icon>
            <span>管理驾驶舱</span>
          </template>
          <el-menu-item index="dashboard">仪表盘</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="3">
          <template #title>
            <el-icon>
              <Setting />
            </el-icon>
            <span>资产管理</span>
          </template>
          <el-menu-item index="/build">楼栋信息</el-menu-item>
          <el-menu-item index="/unit">单元信息</el-menu-item>
          <el-menu-item index="/house">房屋管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="4">
        <template #title>
          <el-icon>
            <location />
          </el-icon>
          <span>业主管理</span>
        </template>
        <el-menu-item index="/ownerInformation">业主信息</el-menu-item>
        <el-menu-item index="/ownerName">业主成员</el-menu-item>
        </el-sub-menu>
       <el-sub-menu index="5">
         <template #title>
          <el-icon>
            <location />
          </el-icon>
          <span>智慧服务</span>
         </template>
         <el-menu-item index="/notice">发布公告</el-menu-item>
         <el-menu-item index="/advertisement">发布广告</el-menu-item>
         <el-menu-item index="/visitor">拜访登记</el-menu-item>
         <el-menu-item index="/phoneComplaint">电话投诉</el-menu-item>
         <el-menu-item index="/publishInformation">发布信息</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="6">
         <template #title>
          <el-icon>
            <location />
          </el-icon>
          <span>智慧停车</span>
         </template>
         <el-menu-item index="parking">停车场管理</el-menu-item>
         <el-menu-item index="placeInfo">车位信息</el-menu-item>
         <el-menu-item index="entryRecord">进场记录</el-menu-item>
         <el-menu-item index="blackAndWhiteList">黑白名单</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="7">
         <template #title>
          <el-icon>
            <location />
          </el-icon>
          <span>设备管理</span>
         </template>
         <el-menu-item index="/deviceAccessControl">设备门禁</el-menu-item>
         <el-menu-item index="/deviceDateSynchronization">设备数据同步</el-menu-item>
         <el-menu-item index="/openingRecord">开门记录</el-menu-item>
         <el-menu-item index="/visitorPhoto">访客留影</el-menu-item>
         <el-menu-item index="/keyApplication">申请钥匙</el-menu-item>
         <el-menu-item index="/keyReview">钥匙审核</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="8">
         <template #title>
          <el-icon>
            <location />
          </el-icon>
          <span>巡检管理</span>
         </template>
         <el-menu-item index="/inspection">巡检</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="9">
         <template #title>
          <el-icon>
            <location />
          </el-icon>
          <span>报表管理</span>
         </template>
        </el-sub-menu>
        <el-sub-menu index="10">
        <template #title>
          <el-icon>
            <location />
          </el-icon>
          <span>系统管理</span>
        </template>
          <el-menu-item index="/user">用户信息</el-menu-item>
          <el-menu-item index="/role">角色管理</el-menu-item>
        </el-sub-menu>
      </el-menu>
      
      
    </el-aside>
  <el-container>
      <el-header>
        <el-card>
          <el-row>
            <el-col :span="18">
              
            </el-col>
            <el-col :span="6">
            {{ user.name }}
            <el-button @click="handleExit">退出</el-button>
            </el-col>
          </el-row>
        </el-card>
      </el-header>
      <el-main>
        <!-- 如果某一部分内容需要根据路由展示，可以使用router-view标签 -->
        <el-card>
          <router-view></router-view>
        </el-card>
      </el-main>
    </el-container>
  </el-container>
</template>
<style scoped></style>

